<template>
	<view class="menucate">
		<!-- 轮播 -->
		<swiper indicator-dots autoplay interval="3000" circular class="container">
			<swiper-item v-for="(item,index) in cateObj.category.bannerUrlList" :key="index" class="">
				<image :src="item" mode=""></image>
			</swiper-item>
		</swiper>

		<!-- 商品展示 -->
		<view class="list">
			<view class="item" v-for="(item,index) in cateObj.itemList" :key="index" @click="goDetail(item)">
				<image :src="item.listPicUrl" mode=""></image>
				<view class="title">{{item.name}}</view>
				<view class="price">{{item.counterPrice}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			cateId: {
				type: Number,
				default: ''
			}
		},
		data() {
			return {
				indexCateList: []
			}
		},
		created() {
			this.getIndexCateList()
		},
		computed: {
			cateObj() {
				console.log('cateId', this.cateId);
				console.log('this.indexCateList.find((ele => ele.category.parentId === this.cateId))', this.indexCateList
					.find(ele => ele.category.parentId === this.cateId));
				return this.indexCateList.find(ele => ele.category.parentId === this.cateId);
			}
		},

		methods: {
			async getIndexCateList() {
				let res = await uni.$http(uni.$base.indexCateList)
				this.indexCateList = res
				console.log('产品', res);
			},
			goDetail(item){
				uni.navigateTo({
					url:'/pages/detail/detail?goodsInfo='+JSON.stringify(item)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		image {
			width: 100%;
			height: 100%;
		}
	}

	.list {
		display: flex;
		flex-wrap: wrap;
		padding: 10rpx;

		.item {
			width: 50%;
			display: flex;
			flex-direction: column;
			align-items: center;

			image {
				width: 344rpx;
				height: 344rpx;
			}

			.title {
				color: #666;
			}

			.price {
				color: #555;
			}
		}
	}
</style>